package com.naizhuai.Model.db.search;

import com.naizhuai.Model.db.user.PersonUserBean;
import com.naizhuai.Model.db.user.UserDataSourse;

import java.util.List;

/**
 * @author：lichenxi
 * @date 2018/2/27 19
 * email：525603977@qq.com
 * Fighting
 */
public class SearchRepository implements SearchDataSourse {
    private static SearchRepository INSTANCE = null;

    private SearchDataSourse localUserData;
    private SearchDataSourse remoteUserData;

    public SearchRepository(SearchDataSourse localUserData, SearchDataSourse remoteUserData) {
        this.localUserData = localUserData;
        this.remoteUserData = remoteUserData;
    }

    public  static SearchRepository getInstance(SearchDataSourse localUserData, SearchDataSourse remoteUserData ){
        if (INSTANCE==null){
            INSTANCE=new SearchRepository(localUserData,remoteUserData);
        }
        return INSTANCE;
    }

    @Override
    public void getUserAsyn(String sid, GetSearchCallback callback) {
        localUserData.getUserAsyn(sid, new GetSearchCallback() {
            @Override
            public void onUserLoaded(SearchHistoryBean user) {
                callback.onUserLoaded(user);
            }

            @Override
            public void onSearchDataArray(List<SearchHistoryBean> beans) {

            }

            @Override
            public void onDataNotAvailable() {
                callback.onDataNotAvailable();
            }
        });
    }

    @Override
    public void searchUserLimit(int limit, GetSearchCallback callback) {
        localUserData.searchUserLimit(limit, new GetSearchCallback() {
            @Override
            public void onUserLoaded(SearchHistoryBean search) {

            }

            @Override
            public void onSearchDataArray(List<SearchHistoryBean> beans) {
                callback.onSearchDataArray(beans);
            }

            @Override
            public void onDataNotAvailable() {
                callback.onDataNotAvailable();
            }
        });
    }

    @Override
    public void saveSearchData(SearchHistoryBean search) {
        localUserData.saveSearchData(search);
    }


    @Override
    public void deleteSearchData(SearchHistoryBean bean) {
        localUserData.deleteSearchData(bean);
    }

}
